<template>
  <el-form ref="form" :model="form" label-width="80px">
    <el-form-item label="姓名">
      <el-input v-model="form.p_name"></el-input>
    </el-form-item>
    <el-form-item label="性别">
      <el-radio-group v-model="form.p_sex">
        <el-radio label="男"></el-radio>
        <el-radio label="女"></el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="年龄">
      <el-input type="number" v-model="form.p_age"></el-input>
    </el-form-item>
    <el-form-item label="爱好">
      <el-select
        v-model="p_hobby"
        @change="selectChange"
        multiple
        placeholder="请选择"
      >
        <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        >
        </el-option>
      </el-select>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="doEdit">立即创建</el-button>
      <el-button>取消</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
const axios = require("axios");

export default {
  data() {
    return {
      p_hobby: [],
      form: {
        p_hobby: [],
      },
      options: [
        {
          value: "爱好1",
          label: "爱好一",
        },
        {
          value: "爱好2",
          label: "爱好二",
        },
        {
          value: "爱好3",
          label: "爱好三",
        },
      ],
      cxx:""
    };
  },
  mounted() {
    if (this.$route.params.row == undefined || this.$route.params.row == "") {
      this.form = {
        p_name: "",
        p_age: "",
        p_sex: "",
        p_hobby: [],
      };
    } else {
      this.form = JSON.parse(this.$route.params.row);
      this.p_hobby = this.form.p_hobby.split(",");
    }
  },
  methods: {
    selectChange(e) {
      console.log(e);
    },
    doEdit() {
      this.form.p_hobby = this.p_hobby.join();
      this.form.p_age = parseInt(this.form.p_age)
      console.log(this.form);
      axios
        .post("https://localhost:44367/api/Person/update", this.form)
        .then(function (response) {
          console.log(response);
        });
    },
  },
};
</script>

<style></style>
